package com.circulardependence.utils.myhutool;
import cn.hutool.core.date.*;
import cn.hutool.http.HttpUtil;

import java.util.Date;
/**
 * Created by IntelliJ IDEA2021.3
 * hutool工具类测试
 * @Author: Tenghw
 * @Date: 2022/08/31  20:03
 * @Description:
 */
@SuppressWarnings("all")
public class HutoolDemo1 {
    public static void main(String[] args) {
        //获取当前日期
        DateTime date = DateUtil.date();
        System.out.println(date);//2022-08-31 20:31:50

        //格式化日期输出
        String formatDate = DateUtil.format(date, "yyyy.MM.dd");
        System.out.println(formatDate);//2022.08.31

        //结果：2022-xx-xx 00:00:00
        String formatDateTime = DateUtil.formatDateTime(date);
        System.out.println(formatDateTime);//2022-08-31 20:31:50

        //结果：00:00:00
        String formatTime = DateUtil.formatTime(date);
        System.out.println( formatTime);//20:31:50

        System.out.println("=====================");
        String dateStr1 = "2022-08-08 08:08:08";
        Date date1 = DateUtil.parse(dateStr1);
        String dateStr2 = "2023-01-01 00:00:00";
        Date date2 = DateUtil.parse(dateStr2);

        // 日期时间差
        long betweenDay = DateUtil.between(date1, date2, DateUnit.MS);

        // 格式化时间差，输出：2天1小时1分4秒
        String formatBetween = DateUtil.formatBetween(betweenDay, BetweenFormatter.Level.SECOND);
        System.out.println(formatBetween);//145天15小时51分52秒
        System.out.println("=====================");

        //一天的开始，结果：2022-xx-01 00:00:00
        Date beginOfDay = DateUtil.beginOfDay(date);

        //一天的结束，结果：2022-xx-01 23:59:59
        Date endOfDay = DateUtil.endOfDay(date);
        System.out.printf("%s %s \n", beginOfDay, endOfDay);//2022-08-31 00:00:00 2022-08-31 23:59:59

        System.out.println("~~~~~~~~~~~~~~~~");
        // 星座
        String zodiac = DateUtil.getZodiac(Month.JUNE.getValue(), 11);
        System.out.println(zodiac);//双子座
        //属相
        String chineseZodiac = DateUtil.getChineseZodiac(2022);
        System.out.println(chineseZodiac);//虎
        System.out.println("~~~~~~~~~~~~~~~~");
        //data1=2022-08-08 08:08:08往后10天的时间为：2022-08-18 08:08:08
        DateTime dateTime = DateUtil.offsetDay(date1, 10);
        System.out.println(dateTime);//2022-08-18 08:08:08

        String s = HttpUtil.get("http://localhost:8080/person/getById/2");
        System.out.println(s);
    }
}
